package com.zy.nft_system.utils;

import lombok.SneakyThrows;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 这是那头猪？
 * @version 1.0
 * @description: TODO
 * @date 2022/10/3 21:06
 */
@Component
public class DateUtils {
    @SneakyThrows
    public static Date dataFormat(Date date){
        //日期格式化类
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //将日期转为指定日期字符串对象
        String s = dateFormat.format(date);

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //将字符串转为对象
        Date parse = format.parse(s);
        return parse;
    }

    public static void main(String[] args) {
        System.out.println(DateUtils.dataFormat(new Date()));
        System.out.println(new Date());
        System.out.println(new Date().getTime() - 86400000);
        System.out.println(new Date(new Date().getTime() - 86400000));
    }
}
